//
//  SubscribeVC.m
//  EducationLive
//
//  Created by Apple on 2017/10/19.
//  Copyright © 2017年 ZhouHao. All rights reserved.
//

#import "SubscribeVC.h"
#import "SubscribeCellNode.h"

@interface SubscribeVC ()<ASTableDelegate, ASTableDataSource>
// UI
@property (nonatomic, strong) ASTableNode *tableNode;

@end

@implementation SubscribeVC

#pragma mark - life cycle

- (instancetype)init
{
    if (self = [super initWithNode:[ASDisplayNode new]]) {
        [self addTableNode];
    }
    return self;
}

- (void)addTableNode
{
    _tableNode = [[ASTableNode alloc] init];
    _tableNode.backgroundColor = RGB_255(245,245,245);
    _tableNode.delegate = self;
    _tableNode.dataSource = self;
    [self.node addSubnode:_tableNode];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 加载表Footer
    [self configureTableView];
    // 加载导航栏item
    [self loadNavItem];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    _tableNode.frame = self.node.bounds;
}
// 加载表Footer
- (void)configureTableView
{
    _tableNode.view.tableFooterView = [[UIView alloc]init];
    _tableNode.view.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - NavigationController Item Title
// 加载导航栏item
- (void)loadNavItem
{
    self.title = @"我的订阅";
}

#pragma mark - ASTableDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (ASCellNodeBlock)tableView:(ASTableView *)tableView nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ASCellNode *(^cellNodeBlock)() = ^ASCellNode *() {
        SubscribeCellNode *cellNode = [[SubscribeCellNode alloc] initWithItem];
        return cellNode;
    };
    return cellNodeBlock;
}

#pragma mark - Tableview Cell Delete
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
    }
}

//修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

//设置进入编辑状态时，Cell不会缩进
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
